package com.woniuxy.microloanserver.util;

import java.math.BigDecimal;
import java.util.regex.Pattern;

/**
 * Description: BigDecimal类型金额格式验证工具
 *
 * @Auther: HanLei
 * @Date: 2021/4/19:17:13
 */
public class MoneyUtil {

    //两位小数金额校验
    public static boolean judgeMoneyDecimal(BigDecimal money) {
        boolean flag = false;
        try {
            if (money != null) {
                String source = money.toString();
                // 判断是否是整数或者是携带一位或者两位的小数
                Pattern pattern = Pattern.compile("^[1-9][0-9]*0{2}$");
                if (pattern.matcher(source).matches()) {
                    flag = true;
                }
            }
        } catch (Exception e) {
            e.getMessage();
        }
        return flag;
    }
}